var role = require("../lib/role");
module.exports = {
	prefix: "/admin_news",
	get: {
		"/by_id/:news_id": function() {
			var admin = role.getAdmin(this);
			var news_id = this.params.news_id;
			this.body = ResponObj("json", admin._getNews(news_id));
		},
		"/list": function() {
			var admin = role.getAdmin(this);
			var query = this.request.query;
			this.body = ResponObj("json", admin.getNewsList(query.num, query.page));
		}
	},
	post: {
		"/add_news": function() {
			var admin = role.getAdmin(this);
			var body = this.request.body;
			var news = admin.addNews(body);
			this.body = ResponObj("json", news);
		}
	},
	put: {
		"/update_news": function() {
			var admin = role.getAdmin(this);
			var news_id = this.params.news_id;
			var body = this.request.body;
			var news = admin.updateNews(body._id, body);
			if (body.back_list) { //以列表信息返回
				this.body = ResponObj("json", admin.getNewsList(body.num, body.page));
			} else {
				this.body = ResponObj("json", news);
			}
		}
	},
	delete: {
		"/delete_news/:news_id": function() {
			var admin = role.getAdmin(this);
			var news_id = this.params.news_id;
			var body = this.request.body;
			admin.removeNews(news_id);
			if (body.back_list) { //以列表信息返回
				this.body = ResponObj("json", admin.getNewsList(body.num, body.page));
			} else {
				this.body = ResponObj("string", "评论删除成功");
			}
		}
	}
}